<template>
  <el-tabs v-model="activeName">
    <el-tab-pane label="爬虫库存" name="first">
      <!-- 包含了爬取渠道 关键词 -->
      <div class="crawler_content">
        <!-- 爬取渠道 -->
        <div class="crawler_content_top_left">
          <span>爬取渠道</span>
          <form>
            <select name="cars" class="crawlingChannel" v-model="data.engineType">
              <option value="1" selected="selected">百度</option>
              <option value="2">搜狗</option>
              <option value="3">360</option>
              <option value="4">微信公众号</option>
            </select>
          </form>
        </div>
        <!-- 关键词 -->
        <div class="crawler_content_top_right">
          <span>关键词</span>
          <input v-model="data.keyword" placeholder="请输入内容"/>
        </div>

      </div>
      <!-- 包含爬取页数和爬取按钮的框 -->
      <div class="crawler_content_bottom">
        <div class="crawler_content_bottom_left">
          <span>爬取页数</span>
          <input type="text" v-model="data.pageSize"/>
        </div>
        <!-- 爬取按钮 -->
        <div class="crawler_content_bottom_right">
          <el-button type="text" class="crawling_button" @click="dialogVisible = true">爬取</el-button>
          <el-dialog
            :modal-append-to-body="false"
            title="确认爬取"
            :visible.sync="dialogVisible"
            width="30%">
            <span>是否确认爬取数据</span>
            <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible = false">否</el-button>
              <el-button type="primary" @click="getCrawler()">是</el-button>
            </span>
          </el-dialog>

        </div>

      </div>

    </el-tab-pane>
    <Modal
      v-model="success"
      title="爬取结果">
      <strong>当前爬取结果成功，请到<span class="tu" @click="$router.push({name: '爬虫资讯库'})">爬虫资讯库</span>进行操作</strong>
    </Modal>
  </el-tabs>
</template>
<script>
export default {
  data () {
    return {
      success: false,
      loading: false,
      activeName: 'first', // 页面默认选择爬虫库存
      dialogVisible: false, // 爬取点击事件的状态
      data: {
        engineType: 1, // 引擎类型，默认百度
        keyword: '', // 关键字
        pageSize: 0// 页面
      }

    }
  },
  methods: {
    openFullScreen2 () {
      this._loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    },
    // 展示数据的框
    open () {
      this.success = true
    },
    // 失败后展示数据的框
    unopen () {
      this.$confirm('<strong>当前爬取结果失败，请重新进行操作</strong>', '爬取结果', {
        dangerouslyUseHTMLString: true
      })
    },
    // 点击爬取开始获取接口数据然后进行展示
    getCrawler () {
      this.openFullScreen2()
      this.dialogVisible = false
      this.loading = true
      this.$http('/stage/spider/startCrawler',
        {
          engineType: this.data.engineType,
          keyword: this.data.keyword,
          pageSize: this.data.pageSize
        }, 'post', res => {
          this._loading.close()
          if (res.data.code == 200) {
            this.open()
          } else {
            this.unopen()
          }
        })
    },
  }

}
</script>
<style lang="less" scoped>
  .tu {
    color: #2D8cF0;
    cursor: pointer;
  }
  // 包含了爬取渠道 关键词
  .crawler_content {
    width: 600px;
    height: 100px;

    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    flex-wrap: wrap;

    .crawler_content_top_left {
      display: flex;
      justify-content: space-between;

      span {
        height: 33px;
        line-height: 33px;
        margin-right: 10px;
      }

      .crawlingChannel {
        width: 100px;

        box-sizing: border-box;

      }

    }

    .crawler_content_top_right {

      input {
        height: 35px;
        margin-left: 10px;
        width: 300px;
      }
    }

  }

  //  包含了爬取页数 爬取结果的框
  .crawler_content_bottom {
    width: 600px;
    height: 100px;

    display: flex;
    justify-content: space-between;
    box-sizing: border-box;

    input {
      width: 100px;

    }

    .crawling_button {
      width: 100px;
      height: 35px;
      line-height: 0px;
      box-shadow: 6px 6px 10px #ABAAAB;
    }
  }

  //包含爬取结果的模块框
  .crawling_results {
    width: 600px;
    height: 400px;

    box-sizing: border-box;
    display: flex;
    justify-content: center;

    .crawling_results_content {
      width: 400px;
      height: 300px;
      border: 1px solid black;
      align-self: center;
      display: flex;
      flex-direction: column;

      span {
        width: 399px;
        height: 30px;
        border-bottom: 1px solid black;
        display: block;
      }

      .crawling_progress {
        width: 350px;
        height: 270px;

        align-self: center;

      }
    }
  }

</style>
